$(function () {

    var teacherId = $("#teacherId").val();
    getBasicInfomation(teacherId);
    
    $('body').on('click','#btn1',function () {
        switchClass($(this));
        getBasicInfomation(teacherId);
    }).on('click','#btn2,#search-answer',function () {
        switchClass($(this));
        getQaAnswerRecordList(1);
    }).on('click','#question-info',function () {//查看问题详情
        var questionId = $(this).data('id');
        var isFree = $(this).data('isfree');
        var url = baseloaction + "/admin/qa/question/freeQuestionInfo?questionId=" + questionId;
        if(isFree == 2){
            url = baseloaction + "/admin/qa/question/noFreeQuestionInfo?questionId=" + questionId;
        }
        getRedirectMenu(url);
    }).on('click','#user-info',function () {
        getRedirectMenu(baseloaction + "/admin/user/cus/userInfo?userId="+ $(this).data('id'));
    }).on('click','#btn3,#search-attend',function () {
        switchClass($(this));
        findGainAttendRecordList(1);
    }).on('click','#btn4,#search-loginLog',function () {
        switchClass($(this));
        findLoginLogList(1);
    });

    /**
     * 获取讲师基本信息
     */
    function getBasicInfomation(teacherId) {
        $.ajax({
            url: baseloaction + '/admin/manage/teacher/teacherInfo',
            data: {"teacherId": teacherId, "flag": true},
            type: 'post',
            dataType: 'text',
            success: function (result) {
                $("#teacher-info").html(result);
            },
            error: function (error) {
                icModale(0,'系统繁忙，请稍后重试');
            }
        })
    }

    /**
     * 查询讲师回答记录
     * @param pageNo
     */
    function getQaAnswerRecordList(pageNo){
        var replyStartTime = $("#start").val();
        var replyEndTime = $("#end").val();
        var params = {"teacherId": teacherId,"replyStartTime": replyStartTime, "replyEndTime": replyEndTime};
        params = JSON.stringify(params);
        ajaxGetListData({
            url: baseloaction + '/admin/manage/teacher/findQaAnswerRecordList',
            params: params,
            pageNo: pageNo,
            contextId: 'teacher-info',
            pageCall: getQaAnswerRecordList,
            callback: function (pageNo) {

            }
        })
    }

    //查询围观收益记录
    function findGainAttendRecordList(pageNo) {
        var beginTime = $("#start").val();
        var endTime = $("#end").val();
        var params = {"receiptorId": teacherId,"beginTime": beginTime, "endTime": endTime};
        params = JSON.stringify(params);
        ajaxGetListData({
            url: baseloaction + '/admin/manage/teacher/findGainAttendRecordList',
            params: params,
            pageNo: pageNo,
            contextId: 'teacher-info',
            pageCall: findGainAttendRecordList,
            callback: function (pageNo) {

            }
        })
    }

    //查询登录记录
    function findLoginLogList(pageNo) {
        var userId = $("#userId").val();
        var startTime = $("#start").val();
        var endTime = $("#end").val();
        var params = {"userId": userId,"startTime": startTime, "endTime": endTime};
        params = JSON.stringify(params);
        ajaxGetListData({
            url: baseloaction + '/admin/manage/teacher/findLoginLogList',
            params: params,
            contextId: 'teacher-info',
            pageNo: pageNo,
            pageCall: findLoginLogList,
            callback: function (pageNo) {
                
            }

        })
    }
    
    function switchClass(obj) {
        obj.parent().addClass('active').siblings().removeClass('active');
    }
});